/**
 * 
 */
package com.wodsy.phoenix.dataservice.cms.service.impl;

import java.lang.reflect.InvocationTargetException;

import org.apache.commons.beanutils.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import com.alibaba.dubbo.config.annotation.Service;
import com.alibaba.dubbo.container.Main;
import com.wodsy.phoenix.datadao.base.IBaseDao;
import com.wodsy.phoenix.datadao.cms.dao.CmsHomePageShopRecDao;
import com.wodsy.phoenix.dataobject.base.Pager;
import com.wodsy.phoenix.dataobject.cms.constants.HomePageObjectType;
import com.wodsy.phoenix.dataobject.cms.model.IdxShopRecommended;
import com.wodsy.phoenix.dataobject.cms.vo.IdxShopRecResp;
import com.wodsy.phoenix.dataservice.base.AbstractBaseService;
import com.wodsy.phoenix.dataservice.cms.aop.AfterOperation;
import com.wodsy.phoenix.dataservice.cms.service.CmsHomePageShopRecService;

/**
 * @author bryan
 *
 */
@Service(interfaceClass = CmsHomePageShopRecService.class, interfaceName = "com.wodsy.phoenix.dataservice.cms.service.CmsHomePageShopRecService")
public class CmsHomePageShopRecServiceImpl extends AbstractBaseService<IdxShopRecommended, Integer>
		implements CmsHomePageShopRecService {
	
	@Autowired
	CmsHomePageShopRecDao cmsHomePageShopRecDao;
	
	@Override
	protected IBaseDao<IdxShopRecommended, Integer> getIBaseDao() {
		return cmsHomePageShopRecDao;
	}
	@Transactional(readOnly=true)
	@Override
	public IdxShopRecResp getOnlineShopReccommendedRec() {
		IdxShopRecommended shop = cmsHomePageShopRecDao.getOnlineShopReccommendedRec();
		IdxShopRecResp resp = new IdxShopRecResp();
		try {
			BeanUtils.copyProperties(resp, shop);
		} catch (IllegalAccessException | InvocationTargetException e) {
			logger.error("object copy error!", e);
		}
		return resp;
	}

	@Transactional(readOnly=true)
	@Override
	public Pager<IdxShopRecommended> searchShopRecommendedRecByOrder(
			Pager<IdxShopRecommended> shopReccommendRes,
			IdxShopRecommended shopRecommendreq) {
		return cmsHomePageShopRecDao.searchShopRecommendedRecByOrder(shopReccommendRes, shopRecommendreq);
	}

	@Transactional(readOnly=false)
	//@AfterManuallyOperation(objectId="#shop_recId",objectStatus="#status",objectType=HomePageObjectType.SHOPRECOMMENDED)
	@Override
	public Integer updateShopRecommendedStatus(int shop_recId, int status) {
		return cmsHomePageShopRecDao.updateGoodsRecommendedStatus(shop_recId, status);
	}
	
	@Transactional(readOnly=false)
	//@AfterManuallyOperation(objectId="#shop_recIds",objectStatus="#status",objectType=HomePageObjectType.SHOPRECOMMENDED)
	@Override
	public Integer updateShopRecommendedStatus(Integer[] shop_recIds, int status) {
		return cmsHomePageShopRecDao.updateGoodsRecommendedStatus(shop_recIds, status);
	}
	
	@Transactional(readOnly=false)
	@AfterOperation(objectId="#shop.id",objectType=HomePageObjectType.SHOPRECOMMENDED,
	offlineTime="#shop.offlineTime",onlineTime="#shop.onlineTime" )
	@Override
	public Integer addNewShopRecommended(IdxShopRecommended shop) {
		Integer newId = cmsHomePageShopRecDao.addNewShopRecommended(shop);
		
		return newId;

	}
	
	@Transactional(readOnly=false)
	@AfterOperation(objectId="#shop.id",objectType=HomePageObjectType.SHOPRECOMMENDED,
	offlineTime="#shop.offlineTime",onlineTime="#shop.onlineTime" )
	@Override
	public void updateNewShopRecommended(IdxShopRecommended shop) {
		cmsHomePageShopRecDao.updateNewShopRecommended(shop);
	}
	
	public static void main(String[] args) {
		Main.main(args);
	}
}
